<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
 */
class Category
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"app","task"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups({"app","task"})
     */
    private $name;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"app","task"})
     */
    private $pic;

    /**
     * @ORM\Column(type="smallint", nullable=true)
     * @Groups({"app"})
     */
    private $sort;

    /**
     * @ORM\Column(type="smallint")
     */
    private $enable;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="sons")
     */
    private $parent;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="parent")
     * @Groups({"app"})
     */
    private $sons;

    /**
     * @ORM\Column(type="smallint", nullable=true)
     */
    private $isHot;

    /**
     * @ORM\Column(type="smallint", nullable=true)
     */
    private $isTop;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $isOnline;

    /**
     * @ORM\Column(type="float", nullable=true)
     */
    private $fee;

    /**
     * @ORM\Column(type="float", nullable=true)
     */
    private $minPay;

    public function __construct()
    {
        $this->sons = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getPic(): ?string
    {
        return $this->pic;
    }

    public function setPic(?string $pic): self
    {
        $this->pic = $pic;

        return $this;
    }

    public function getSort(): ?int
    {
        return $this->sort;
    }

    public function setSort(?int $sort): self
    {
        $this->sort = $sort;

        return $this;
    }

    public function getEnable(): ?int
    {
        return $this->enable;
    }

    public function setEnable(int $enable): self
    {
        $this->enable = $enable;

        return $this;
    }

    public function getParent(): ?self
    {
        return $this->parent;
    }

    public function setParent(?self $parent): self
    {
        $this->parent = $parent;

        return $this;
    }

    /**
     * @return Collection|self[]
     */
    public function getSons(): Collection
    {
        return $this->sons;
    }

    public function addSon(self $son): self
    {
        if (!$this->sons->contains($son)) {
            $this->sons[] = $son;
            $son->setParent($this);
        }

        return $this;
    }

    public function removeSon(self $son): self
    {
        if ($this->sons->contains($son)) {
            $this->sons->removeElement($son);
            // set the owning side to null (unless already changed)
            if ($son->getParent() === $this) {
                $son->setParent(null);
            }
        }

        return $this;
    }

    public function getIsHot(): ?int
    {
        return $this->isHot;
    }

    public function setIsHot(?int $isHot): self
    {
        $this->isHot = $isHot;

        return $this;
    }

    public function getIsTop(): ?int
    {
        return $this->isTop;
    }

    public function setIsTop(?int $isTop): self
    {
        $this->isTop = $isTop;

        return $this;
    }

    public function getIsOnline(): ?int
    {
        return $this->isOnline;
    }

    public function setIsOnline(?int $isOnline): self
    {
        $this->isOnline = $isOnline;

        return $this;
    }

    public function getFee(): ?float
    {
        return $this->fee;
    }

    public function setFee(?float $fee): self
    {
        $this->fee = $fee;

        return $this;
    }

    public function getMinPay(): ?float
    {
        return $this->minPay;
    }

    public function setMinPay(?float $minPay): self
    {
        $this->minPay = $minPay;

        return $this;
    }
}
